using System.Collections;
using System.Collections.Generic;
using Backpack;
using SO;
using UnityEngine;

[RequireComponent(typeof(BoxCollider2D))]
public class ItemOnWorld : MonoBehaviour
{
    public int itemID;

    private SpriteRenderer spriteRenderer;
    [SerializeField] private ItemDataSO itemDataSO;
    private void Awake()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        itemDataSO = ItemConfigModel.Instance.GetData(itemID);

        spriteRenderer.sprite = itemDataSO.spriteOnWorld;
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            //Add item to inventory
            BackpackSystem.Instance.AddItem(itemDataSO);
            Destroy(gameObject);
        }
    }
}
